package top.wenzz.commons.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import top.wenzz.commons.annotation.Query;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;

/**
 * Created by 钟廷员 on 2016/9/5.
 */
@MappedSuperclass
@Data
@AllArgsConstructor
public class DataEntity<T> {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Query
    @JsonProperty("key")
    private int id;
    @Version
    @Column(name = "version_control")
    private int version;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "create_time")
    private Timestamp createTime;
    @JsonIgnore
    @Column(length = 11, name = "create_user_id")
    private String createUserId;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "update_time")
    private Timestamp updateTime;
    @JsonIgnore
    @Column(length = 11, name = "update_user_id")
    private String updateUserId;

    public DataEntity() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        DataEntity<?> that = (DataEntity<?>) o;

        return id == that.id;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + id;
        return result;
    }
}
